#pragma once

#include <QThread>

template <class QObj>
class Threaded : public QObj
{
    QThread _thread;
public:
    template<typename... Arguments>
    explicit Threaded(Arguments... args) :
        QObj(args...)
    {
        Q_ASSERT_X(this->parent() == nullptr, "Threaded()",
                   "Threaded QOject can't have parent!");
        this->moveToThread(&_thread);
        _thread.start();
    }

    ~Threaded() override
    {
        _thread.quit();
        _thread.wait();
    }

    QObj &operator()() { return *this; }
    const QObj &operator()() const { return *this; }
};
